//处理登录的数据和服务器端交互
var loginManager = {};
loginManager.login = function () {
    $.ajax({
        url: '/LoginServlet',
        type: 'post',
        data: {
            "loginName": $("#loginName").val(),
            "loginPwd": $("#loginPwd").val()
        },
        dataType: 'json',
        success: function (result) {
            console.log(result);
            if (result.status > 0) {
                toastr['success']("登录成功");

                // 在应用持久化数据
                window.localStorage.setItem("loginName", result.data.staffName);
                window.localStorage.setItem("staffId", result.data.staffId);
                window.localStorage.setItem("id", result.data.roleId);
                window.localStorage.setItem("phone", result.data.phone);
                window.localStorage.setItem("idCard", result.data.idCard);
                window.localStorage.setItem("address", result.data.address);
                window.localStorage.setItem("createdTime", result.data.createdTime);
                window.localStorage.setItem("password", result.data.password);
                window.location.href = "../index/views/main.html";
            } else {
                toastr['error']("登录失败");
            }
        }
    })
}